--[[

xp.lua

]]

-- Function: Respond to the whisper about xp
function LXP_WhisperXP(recipient)
	local myMessage		= "";

	if (UnitLevel("player") == 85) then
		myMessage = LXP_MSG_60TELL;
	else
		local LXP_XPCur		= UnitXP("player");
		local LXP_XPMax		= UnitXPMax("player");

		local LXP_XPLeft	= LXP_XPMax - LXP_XPCur;
		local LXP_XPPer		= LXP_SF_ValueToPrecision(((LXP_XPCur/LXP_XPMax) * 100), 2);
		local LXP_XPLPer	= LXP_SF_ValueToPrecision(((LXP_XPLeft/LXP_XPMax) * 100), 2);

		myMessage = format(LXP_MSG_RETURN, LXP_XPCur, LXP_XPMax, LXP_XPPer, LXP_XPLeft, LXP_XPLPer);

		local LXP_RestCur	= 0;
		local LXP_RestPer	= 0;

		if (GetRestState() == 1) then
			LXP_RestCur	= (tonumber(GetXPExhaustion()) / 2);
			LXP_RestPer	= LXP_SF_ValueToPrecision(((LXP_RestCur/LXP_XPMax) * 100), 2);		
			myMessage = myMessage..format(LXP_MSG_RETURNREST, LXP_RestCur, LXP_RestPer);
		end
	end

	-- Send the message.
	SendChatMessage(myMessage, "WHISPER", GetDefaultLanguage("player"), recipient);
end

-- Function: Update the xp status bar with the remaining xp and rest xp
function LXP_UpdateXPBar()
	local LXP_XPCur	= UnitXP("player");
	local LXP_XPMax	= UnitXPMax("player");
	local LXP_XPLeft	= LXP_XPMax - LXP_XPCur;

	if (GetRestState() == 1) then
		local LXP_RestCur	= (tonumber(GetXPExhaustion()) / 2);
		LysXP_Frame_BarText:SetText(format("(Left: %d / Rested: %d)", LXP_XPLeft, LXP_RestCur));
	else
		LysXP_Frame_BarText:SetText(format("(Left: %d)", LXP_XPLeft));
	end
	
end

-- Function: Update the xp status bar with the Pet's remaining xp and rest xp
function LXP_UpdatePetXPBar()
	-- Pet XP Calc's
	local LXP_PetXPCur, LXP_PetXPMax = GetPetExperience();

	if (LXP_PetXPMax == 0) then
		LysXP_Frame_PetBarText:SetText("");
		return;
	end

	if (UnitLevel("player") == UnitLevel("pet")) then
		LysXP_Frame_PetBarText:SetText("");
		return;
	end
	
	local LXP_PetXPLeft = LXP_PetXPMax - LXP_PetXPCur;

	LysXP_Frame_PetBarText:SetText(format("     (Pet: %d / %d)", LXP_PetXPLeft, LXP_PetXPMax));
end

